package com.laiyima.zhongjiang.linghuilv.demo.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.bean.PointsDetailsBean;

import java.text.DecimalFormat;
import java.util.List;

public class PdetailsAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<PointsDetailsBean> mPointsDetailsBean;
    private String TAG="AgentAdapter";
    public PdetailsAdapter(Context context, List<PointsDetailsBean> maxPointsDetailsBeanDatas){
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mPointsDetailsBean = maxPointsDetailsBeanDatas;
    }
    @Override
    public int getCount() {
        return mPointsDetailsBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mPointsDetailsBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.pointdetails_item,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.Pd_uid = convertView.findViewById(R.id.pd_uid);
            viewHolder.pd_create_time = convertView.findViewById(R.id.pd_create_time);
            viewHolder.pd_wtype = convertView.findViewById(R.id.pd_wtype);
            viewHolder.pd_remark = convertView.findViewById(R.id.pd_remark);
            viewHolder.pd_money = convertView.findViewById(R.id.pd_money);
            viewHolder.imageView=convertView.findViewById(R.id.poindetail_item_image);
            convertView.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        PointsDetailsBean pointsDetailsBean = mPointsDetailsBean.get(position);
        viewHolder.Pd_uid.setText(pointsDetailsBean.getUid());
        viewHolder.pd_create_time.setText(pointsDetailsBean.getCreate_time());
        viewHolder.pd_wtype.setText(pointsDetailsBean.getWtype());
        String type=pointsDetailsBean.getWtype();
        if(type.equals("积分返现")){
            viewHolder.imageView.setImageResource(R.drawable.pd1);
        }else if(type.equals("服务商收益")){
            viewHolder.imageView.setImageResource(R.drawable.pd2);
        }else if(type.equals("消费收益")){
            viewHolder.imageView.setImageResource(R.drawable.pd3);
        }else if(type.equals("推广收益")){
            viewHolder.imageView.setImageResource(R.drawable.pd4);
        }else if(type.equals("积分兑换")){
            viewHolder.imageView.setImageResource(R.drawable.pd5);
        }else {
            viewHolder.imageView.setImageResource(R.drawable.pd7);
        }


        viewHolder.pd_remark.setText(pointsDetailsBean.getRemark());

        String s=pointsDetailsBean.getMoney();
        s=s.substring(0,1);
        if(s.equals("-")){
            Double a1 = Double.parseDouble(pointsDetailsBean.getMoney());
            DecimalFormat decimalFormatq = new DecimalFormat("0.00");
            String b1 = decimalFormatq.format(a1);

            viewHolder.pd_money.setText(b1+"");
            viewHolder.pd_money.setTextColor(Color.parseColor("#333333"));
        }else{

            Double a1 = Double.parseDouble(pointsDetailsBean.getMoney());
            DecimalFormat decimalFormatq = new DecimalFormat("0.00");
            String b1 = decimalFormatq.format(a1);
            viewHolder.pd_money.setText("+"+b1+"");
            viewHolder.pd_money.setTextColor(Color.parseColor("#F0562E"));
        }

        return convertView;
    }

    public static class ViewHolder{
        TextView Pd_uid;
        TextView pd_create_time;
        TextView pd_wtype;
        TextView pd_remark;
        TextView pd_money;
        ImageView imageView;
    }
}
